package com.itheima.set;

import java.util.Comparator;
import java.util.TreeSet;

public class Test {
    public static void main(String[] args) {
        TreeSet<Teacher> Tset1 = getTeachers();
        TreeSet<Teacher> Tset2 = getTeachers();

        TreeSet<Student> sset2 = getStudents();
        TreeSet<Student> sset1 = getStudents();

        Student s1=new Student("1","李四");
        Student s2=new Student("262","王五");
        Student s3=new Student("3","赵六");
        Student s4=new Student("33","刘武");
        Student s5=new Student("5","林萧");
        sset2.add(s1);
        sset2.add(s2);
        sset2.add(s3);
        sset2.add(s4);
        sset2.add(s5);

        Student ss1=new Student("6","李四");
        Student ss2=new Student("75","王五");
        Student ss3=new Student("8","赵六");
        Student ss4=new Student("9","刘武");
        Student ss5=new Student("10","林萧");
        sset1.add(ss1);
        sset1.add(ss2);
        sset1.add(ss3);
        sset1.add(ss4);
        sset1.add(ss5);

        Teacher t1=new Teacher("001","张飒",sset1);
        Teacher t2=new Teacher("002","张三飒",sset2);
        System.out.println(t1);
        System.out.println(t2);


        //  Teacher<Student> t3=new Teacher<>();




    }

    private static TreeSet<Teacher> getTeachers() {
        return new TreeSet<Teacher>(new Comparator<Teacher>() {
                @Override
                public int compare(Teacher o1, Teacher o2) {
                    int result=o1.getTid().compareTo(o2.getTid());
                    result=result==0?o1.getName().compareTo(o2.getName()):result;
                    return result;
                }
            });
    }

    private static TreeSet<Student> getStudents() {
        return new TreeSet<Student>(new Comparator<Student>() {
                @Override
                public int compare(Student o1, Student o2) {
                    int result=o2.getSid().length()-o1.getSid().length();
                     result=o2.getSid().length()-o1.getSid().length()==0?o2.getSid().compareTo(o1.getSid()):o2.getSid().length()-o1.getSid().length();
                    result=result==0?o2.getName().compareTo(o1.getName()):result;
                    return result;
                }
            });
    }
}
